package com.bw.services.IM

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bw.services.R

class FriendListAdapter(
    private val friends: List<Friend>,
    private val onItemClick: (Friend) -> Unit
) : RecyclerView.Adapter<FriendListAdapter.FriendViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_friend, parent, false)
        return FriendViewHolder(view)
    }

    override fun onBindViewHolder(holder: FriendViewHolder, position: Int) {
        holder.bind(friends[position])
        holder.itemView.setOnClickListener { onItemClick(friends[position]) }
    }

    override fun getItemCount(): Int = friends.size

    class FriendViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val avatar: ImageView = itemView.findViewById(R.id.iv_avatar)
        private val nickname: TextView = itemView.findViewById(R.id.tv_nickname)
        fun bind(friend: Friend) {
            // 头像加载可用第三方库，这里用默认
            nickname.text = friend.nickname
        }
    }
}

// 好友数据类
data class Friend(val username: String, val nickname: String, val avatarUrl: String?) 